// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.sql.SQLException;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.DisabledCommand;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;
import zombie.network.ServerWorldDatabase;

@DisabledCommand
@CommandName(
    name = "addusertowhitelist"
)
@CommandArgs(
    required = {"(.+)"}
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_AddWhitelist"
)
@RequiredRight(
    requiredRights = 48
)
public class AddUserToWhiteListCommand extends CommandBase {
    public AddUserToWhiteListCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() throws SQLException {
        String string = this.getCommandArg(Integer.valueOf(0));
        if (!ServerWorldDatabase.isValidUserName(string)) {
            return "Invalid username \"" + string + "\"";
        } else {
            for (int _int = 0; _int < GameServer.udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(_int);
                if (udpConnection.username.equals(string)) {
                    if (udpConnection.password != null && !udpConnection.password.equals("")) {
                        LoggerManager.getLogger("admin")
                            .write(this.getExecutorUsername() + " created user " + udpConnection.username + " with password " + udpConnection.password);
                        return ServerWorldDatabase.instance.addUser(udpConnection.username, udpConnection.password);
                    }

                    return "User " + string + " doesn't have a password.";
                }
            }

            return "User " + string + " not found.";
        }
    }
}
